using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace Sio.Mdm.Utils
{
    /// <summary>
    /// Class for writting event to system event log
    /// </summary>
    public class LoggerEventLogWriter : ILoggerWriter
    {
        #region Construciton
        /// <summary>
        /// Initialize new instance of event log writter with passed source name
        /// </summary>
        /// <param name="sourceName">Source name to use for event log</param>
        public LoggerEventLogWriter(string sourceName)
        {
            EventLog.Source = sourceName;
        }
        #endregion

        #region Properties

        #region Private

        #region EventLog
        private EventLog _eventLog;
        private EventLog EventLog
        {
            get
            {
                if (null == _eventLog)
                {
                    _eventLog = new EventLog();
                }

                return _eventLog;
            }
        }
        #endregion

        #endregion

        #endregion

        #region ILoggerWriter Members
        void ILoggerWriter.WriteMessage(Logger.MessageType type, DateTime timeStamp, string message)
        {
            try
            {
                EventLog.WriteEntry(message);
            }
            catch (Exception)
            {
            }
        }
        #endregion
    }
}
